/**
 * Created by cuppi on 2017/7/24.
 */

var express = require('express');
var router = express.Router();
var path = require('path');
var PublishManager = require('../util/PublishManager');

router.get('/', function (req, res, next) {
    // var accessKey = 'qoFeXFeK9LuEYXVav8e6KVibE5te3WpxUt b_jaPZ';
    // var secretKey = '_y7xBbKbobKGHuI31qxR_bFwFWBoTRtZBGSifHMP';
    // var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    //
    // var options = {
    //     scope: 'uglyfilm-test',
    // };
    // var putPolicy = new qiniu.rs.PutPolicy(options);
    // var uploadToken = putPolicy.uploadToken(mac);
    // console.log(uploadToken);
    // res.json({data: uploadToken, errorCode: 0, message: ''});
});

router.post('/', function (req, res, next) {
    let project = req.query.project;
    if (req.body.project){
        project = req.body.project;
    }
    if (project === 'cmbc'){
        PublishManager.updateDist().then(data => {
            res.json({data: '发布成功', errorCode: 0, message: ''});
        }, error => {
            res.json({data: '', errorCode: -1, message: '发布失败'});
        }).catch(error => {
            res.json({data: '', errorCode: -1, message: '发布失败 throw error'});
        })
        return;
    }

    res.json({data: '', errorCode: -1, message: 'don\'t find the project parameters'});
});

module.exports = router;